import os
import inspect

# try to import an environment first
try:
  Import('env')
except:
  exec open("../build/build-env.py")
  env = Environment()

# on mac we have to tell the linker to link against the C++ library
if env['PLATFORM'] == "darwin":
  env.Append(LINKFLAGS = "-lstdc++")

# on windows we have to do /bigobj
if env['PLATFORM'] == "win32" or env['PLATFORM'] == "win64":
  env.Append(CPPFLAGS = "/bigobj")

# find all .cus & .cpps in the current directory
sources = []
directories = ['.']
extensions = ['*.cu', '*.cpp']

if env['backend'] == 'cuda' or env['backend'] == 'ocelot':
  directories.append('cuda')
elif env['backend'] == 'omp':
  directories.append('omp')

for dir in directories:
  for ext in extensions:
    regexp = os.path.join(dir, ext)
    sources.extend(env.Glob(regexp))

# add the directory containing this file to the include path
this_file = inspect.currentframe().f_code.co_filename
this_dir = os.path.dirname(this_file)
env.Append(CPPPATH = [this_dir])

tester = env.Program('tester', sources)

